<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的收藏 - 校园失物招领系统</title>
    <link rel="stylesheet" href="/css/common.css">
</head>
<body>
    <div class="container">
        <nav class="navbar">
            <div class="nav-left"><h1>校园失物招领系统</h1></div>
            <div class="nav-right">
                <span id="username"></span>
                <a href="/notifications" class="nav-link">通知 <span id="unreadCount" class="badge"></span></a>
                <a href="/profile" class="nav-link">个人中心</a>
                <a href="javascript:void(0)" onclick="logout()" class="nav-link">退出</a>
            </div>
        </nav>

        <div class="main-content">
            <div class="sidebar">
                <a href="/home" class="menu-item">首页</a>
                <a href="/lost" class="menu-item">失物信息</a>
                <a href="/found" class="menu-item">招领信息</a>
                <a href="/lost/publish" class="menu-item">发布失物</a>
                <a href="/found/publish" class="menu-item">发布招领</a>
                <a href="/my/lost" class="menu-item">我的失物</a>
                <a href="/my/found" class="menu-item">我的招领</a>
                <a href="/claims/sent" class="menu-item">发出的认领</a>
                <a href="/claims/received" class="menu-item">收到的认领</a>
                <a href="/favorites" class="menu-item active">我的收藏</a>
                <div id="adminMenu"></div>
            </div>

            <div class="content">
                <h2>我的收藏</h2>

                <div class="section">
                    <h3>收藏的失物</h3>
                    <div id="lostList"></div>
                </div>

                <div class="section">
                    <h3>收藏的招领</h3>
                    <div id="foundList"></div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        loadUser();
        loadUnreadCount();

        $.get('/api/favorite/list', function(res) {
            if (res.code === 200) {
                const lostItems = res.data.lostItems;
                const foundItems = res.data.foundItems;

                if (lostItems.length === 0) {
                    $('#lostList').html('<p class="empty">暂无收藏的失物</p>');
                } else {
                    const html = lostItems.map(item => `
                        <div class="item-card">
                            <h4><a href="/lost/detail?id=${item.id}">${item.title}</a></h4>
                            <p>${item.description || ''}</p>
                            <div class="item-meta">
                                <span>分类：${item.categoryName}</span>
                                <span>地点：${item.lostLocation}</span>
                                <span>时间：${formatDate(item.lostTime)}</span>
                            </div>
                        </div>
                    `).join('');
                    $('#lostList').html(html);
                }

                if (foundItems.length === 0) {
                    $('#foundList').html('<p class="empty">暂无收藏的招领</p>');
                } else {
                    const html = foundItems.map(item => `
                        <div class="item-card">
                            <h4><a href="/found/detail?id=${item.id}">${item.title}</a></h4>
                            <p>${item.description || ''}</p>
                            <div class="item-meta">
                                <span>分类：${item.categoryName}</span>
                                <span>地点：${item.foundLocation}</span>
                                <span>时间：${formatDate(item.foundTime)}</span>
                            </div>
                        </div>
                    `).join('');
                    $('#foundList').html(html);
                }
            }
        });
    </script>
</body>
</html>

